package com.dapeis.core.utils.json;

import java.lang.reflect.Type;
import java.util.Date;

import com.ag.utils.DateUtils;
import com.ag.utils.json.AGsonBuilder;
import com.dapeis.core.utils.DBConfigUtils;
import com.dapeis.core.utils.RequirementConfig;
import com.dapeis.core.utils.StylistConstants;
import com.dapeis.domain.ext.TaskOrderExt;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

/**
 * @author 作者 E-mail: hzyuanyong@126.com
 * @version 创建时间：2017年5月15日 下午3:24:29 类说明
 */
public class TaskOrderGsonAdapter implements JsonSerializer<TaskOrderExt> {

    @Override
    public JsonElement serialize(TaskOrderExt src, Type typeOfSrc,
	    JsonSerializationContext context) {
	JsonObject json = new JsonObject();
	json.addProperty("orderId", src.getId().toString());
	json.addProperty(
		"time",
		null == src.getTaskTime() ? new String() : DateUtils.format(
			"MM-dd HH:mm", new Date(src.getTaskTime() * 1000)));
	json.addProperty("status", StylistConstants.getOrderStatusStr(src));
	json.addProperty(
		"age",
		null == src.getUserExt().getUserInformation() ? new String()
			: StylistConstants.getAge(src.getUserExt()
				.getUserInformation().getBirthday() * 1000));
	json.addProperty("headImg", src.getUserExt().getHeadImg());
	json.addProperty("nickName", src.getUserExt().getNickName());
	json.addProperty("remark", src.getRequirement().getRemark());
	json.add(
		"scene",
		AGsonBuilder.create().toJsonTree(
			DBConfigUtils.paserRequiremntSceneAndShop(src
				.getRequirement().getSceneCode(),
				RequirementConfig.CHANG_JING_PRE)));
	json.add(
		"shop",
		AGsonBuilder.create().toJsonTree(
			DBConfigUtils.paserRequiremntSceneAndShop(src
				.getRequirement().getShop(),
				RequirementConfig.LADY_SHOP_CHOOSE)));
	json.addProperty("time", DBConfigUtils.unixTime2ago(src.getPayTime()));
	json.addProperty("sex",
		null == src.getUserExt().getUserInformation() ? new String()
			: src.getUserExt().getUserInformation().getSex()
				.toString());
	json.addProperty("type",
		RequirementConfig.getTypeName(src.getRequirement().getType()));

	return json;
    }

}